home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / comm.swg / 0017_Very Complete FOSSIL Unit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-08-17  |  11.6 KB  |  515 lines

  1. Unit FWizard;
  2.  
  3. {/
  4.       Fossil Wizard Unit v1.0 by Steve Connet - Tuesday, Jan. 19, 1993
  5.  
  6.        This program provides an easy interface to access the routines
  7.        provided by a fossil driver.
  8. //}
  9.  
  10. INTERFACE
  11. Function SetBaud(Port, Baud : Word; Parms : Byte) : Boolean;
  12. Function OutBufferFull(Port : Word) : Boolean;
  13. Function CharWaiting(Port : Word) : Boolean;
  14. Function ComReadChar(Port : Word) : Char;
  15. Function CarrierDetected(Port : Word) : Boolean;
  16. Function ModemRinging(Port : Word) : Boolean;
  17. Function FossilPresent : Boolean;
  18. Function RemoteAnsiDetected(Port : Word) : Boolean;
  19. Function LocalAnsiDetected : Boolean;
  20. Function RemoteAvatarDetected(Port : Word) : Boolean;
  21.  
  22. Procedure ActivatePort(Port : Word);
  23. Procedure DTR(Port : Word; Action : Byte);
  24. Procedure ReBoot(Action : Byte);
  25. Procedure DeActivatePort(Port : Word);
  26. Procedure ComWriteChar(Port : Word; Ch : Char);
  27. Procedure ClearOutBuffer(Port : Word);
  28. Procedure ClearInBuffer(Port : Word);
  29. Procedure FlowControl(Port : Word; XON_XOFFR, XON_XOFFT, RTS_CTS : Boolean);
  30. Procedure WatchDog(Port : Word; Action : Byte);
  31. Procedure Chat(Port : Word);
  32. Procedure ComWrite(Port : Word; Msg : String);
  33. Procedure ComWriteln(Port : Word; Msg : String);
  34. Procedure Wait(Seconds : Word);
  35. Procedure GetCursor(VAR x, y : Byte);
  36. Procedure SetCursor(Port : Word; x, y : Byte);
  37. Procedure SendBreak(Port : Word);
  38. Procedure ComReadln(Port : Word; VAR Msg : String; Count : Byte);
  39. Procedure CLS(Port : Word);
  40.  
  41. CONST
  42.   N81=$03; E81 =$1b; O81 =$0b; LOWER=$00; CTS =$10; RDA =$01; XONR=$01;
  43.   N82=$07; E82 =$1f; O82 =$0f; RAISE=$01; DSR =$20; THRE=$20; XONT=$08;
  44.   N71=$02; E71 =$1a; O71 =$0a; COLD =$00; RI  =$40; TSRE=$40; RTS =$02;
  45.   N72=$06; E72 =$1e; O72 =$0e; WARM =$01; DCD =$80; ON  =$01; OFF =$00;
  46.   Esc=#27; COM1=$00; COM2=$01; COM3 =$02; COM4=$03;
  47.  
  48. IMPLEMENTATION
  49. Uses Crt;
  50.  
  51. Function SetBaud(Port, Baud : Word; Parms : Byte) : Boolean;
  52. VAR Dummy : Word;
  53. Begin
  54.   Case Baud of
  55.     300:   Baud := $40;    { 01000000 }
  56.     600:   Baud := $60;    { 01100000 }
  57.     1200:  Baud := $80;    { 10000000 }
  58.     2400:  Baud := $a0;    { 10100000 }
  59.     4800:  Baud := $c0;    { 11000000 }
  60.     9600:  Baud := $e0;    { 11100000 }
  61.     19200: Baud := $00;    { 00000000 }
  62.     38400,
  63.     14400,
  64.     16800: Baud := $20;    { 00100000 }
  65.   End;
  66.   Parms := Parms OR Baud;  { merge baud bits with parm bits }
  67.   Asm
  68.     mov ah,00h
  69.     mov al,parms
  70.     mov dx,port
  71.     int 14h
  72.     mov dummy,ax
  73.   End;
  74.   SetBaud := ((Dummy AND CTS) = CTS) or     { clear to send }
  75.              ((Dummy AND DSR) = DSR) or     { data set ready }
  76.              ((Dummy AND RI)  = RI)  or     { ring indicator }
  77.              ((Dummy AND DCD) = DCD)        { data carrier detect }
  78. End;
  79.  
  80. Function OutBufferFull(Port : Word) : Boolean;
  81. VAR Dummy : Byte;
  82. Begin
  83.   Asm
  84.     mov ah,03h
  85.     mov dx,port
  86.     int 14h
  87.     mov dummy,ah
  88.   End;
  89.   OutBufferFull := ((Dummy AND THRE) <> THRE) or  { room in out buffer }
  90.                    ((Dummy AND TSRE) <> TSRE)     { out buffer empty }
  91. End;
  92.  
  93. Function CharWaiting(Port : Word) : Boolean;
  94. VAR Dummy : Byte;
  95. Begin
  96.   Asm
  97.     mov ah,03h
  98.     mov dx,port
  99.     int 14h
  100.     mov dummy,ah
  101.   End;
  102.   CharWaiting := (Dummy AND RDA) = RDA        { character waiting }
  103. End;
  104.  
  105. Function ComReadChar(Port : Word) : Char;
  106. VAR Dummy : Byte;
  107. Begin
  108.   Asm
  109.     mov ah,02h
  110.     mov dx,port
  111.     int 14h
  112.     mov dummy,al
  113.   End;
  114.   ComReadChar := Char(Dummy)
  115. End;
  116.  
  117. Function CarrierDetected(Port : Word) : Boolean;
  118. VAR Dummy : Byte;
  119. Begin
  120.   Asm
  121.     mov ah,03h
  122.     mov dx,port
  123.     int 14h
  124.     mov dummy,al
  125.   End;
  126.   CarrierDetected := (Dummy AND DCD) = DCD       { carrier detected }
  127. End;
  128.  
  129. Function ModemRinging(Port : Word) : Boolean;
  130. VAR Dummy : Byte;
  131. Begin
  132.   Asm
  133.     mov ah,03h
  134.     mov dx,port
  135.     int 14h
  136.     mov dummy,al
  137.   End;
  138.   ModemRinging := (Dummy AND RI) = RI       { ring indicated }
  139. End;
  140.  
  141. Function FossilPresent : Boolean;
  142. VAR Dummy : Word;
  143. Begin
  144.   Asm
  145.     mov ah,04h
  146.     mov dx,00ffh
  147.     int 14h
  148.     mov dummy,ax
  149.   End;
  150.   FossilPresent := Dummy = $1954;
  151. End;
  152.  
  153. Function RemoteAnsiDetected(Port : Word) : Boolean;
  154. VAR Dummy : Char;
  155. Begin
  156.   If Not OutBufferFull(Port) then
  157.   Begin
  158.     ComWriteChar(Port, #27); ComWriteChar(Port, '[');
  159.     ComWriteChar(Port, '6'); ComWriteChar(Port, 'n')
  160.   End;
  161.   If CharWaiting(Port) then
  162.      RemoteAnsiDetected := ComReadChar(Port) in [#27,'0'..'9','[','H'] else
  163.      RemoteAnsiDetected := False;
  164.   ClearInBuffer(Port)
  165. End;
  166.  
  167. Function LocalAnsiDetected : Boolean;
  168. VAR Dummy : Byte;
  169. Begin
  170.   Asm
  171.     mov ah,1ah                { detect ANSI.SYS device driver }
  172.     mov al,00h
  173.     int 2fh
  174.     mov dummy,al
  175.   End;
  176.   LocalAnsiDetected := Dummy = $FF
  177. End;
  178.  
  179. Function RemoteAvatarDetected(Port : Word) : Boolean;
  180. Begin
  181.   If Not OutBufferFull(Port) then
  182.   Begin
  183.     ComWriteChar(Port, ' '); ComWriteChar(Port, ' ');
  184.     ComWriteChar(Port, ' ');
  185.   End;
  186.   If CharWaiting(Port) then
  187.      RemoteAvatarDetected := ComReadChar(Port) in ['A','V','T'] else
  188.      RemoteAvatarDetected := False;
  189.   ClearInBuffer(Port)
  190. End;
  191.  
  192.  
  193. Procedure ActivatePort(Port : Word); Assembler;
  194. Asm
  195.   mov ah,04h
  196.   mov dx,port
  197.   int 14h
  198. End;
  199.  
  200. Procedure DTR(Port : Word; Action : Byte); Assembler;
  201. Asm
  202.   mov ah,06h
  203.   mov al,action
  204.   mov dx,port
  205.   int 14h
  206. End;
  207.  
  208. Procedure ReBoot(Action : Byte); Assembler;
  209. Asm
  210.   mov ah,17h
  211.   mov al,action
  212.   int 14h
  213. End;
  214.  
  215. Procedure DeActivatePort(Port : Word); Assembler;
  216. Asm
  217.   mov ax,05h
  218.   mov dx,port
  219.   int 14h
  220. End;
  221.  
  222. Procedure ComWriteChar(Port : Word; Ch : Char);
  223. VAR Dummy : Byte;
  224. Begin
  225.   Dummy := Ord(Ch);
  226.   Asm
  227.     mov ah,01h
  228.     mov al,dummy
  229.     mov dx,port
  230.     int 14h
  231.   End;
  232. End;
  233.  
  234. Procedure ClearOutBuffer(Port : Word); Assembler;
  235. Asm
  236.   mov ah,09h
  237.   mov dx,port
  238.   int 14h
  239. End;
  240.  
  241. Procedure ClearInBuffer(Port : Word); Assembler;
  242. Asm
  243.   mov ah,0ah
  244.   mov dx,port
  245.   int 14h
  246. End;
  247.  
  248. Procedure FlowControl(Port : Word; XON_XOFFR, XON_XOFFT, RTS_CTS : Boolean);
  249. VAR Dummy : Byte;
  250. Begin
  251.   Dummy := $00;
  252.   If XON_XOFFR then                 { Xon/Xoff receive enable }
  253.      Dummy := Dummy OR XONR else    { set bit 0 on }
  254.      Dummy := Dummy AND XONR;       { set bit 0 off }
  255.   If XON_XOFFT then                 { Xon/Xoff transmit enable }
  256.      Dummy := Dummy OR XONT else    { set bit 3 on }
  257.      Dummy := Dummy AND XONT;       { set bit 3 off }
  258.   If RTS_CTS then                   { RTS_CTS enabled }
  259.      Dummy := Dummy OR RTS else     { set bit 1 on }
  260.      Dummy := Dummy AND RTS;        { set bit 1 off }
  261.   Asm
  262.     mov ah,0fh
  263.     mov al,dummy
  264.     mov dx,port
  265.     int 14h
  266.   End
  267. End;
  268.  
  269. Procedure WatchDog(Port : Word; Action : Byte); Assembler;
  270. Asm
  271.   mov ah,14h
  272.   mov al,action
  273.   mov dx,port
  274.   int 14h
  275. End;
  276.  
  277. Procedure Chat(Port : Word);
  278.  
  279. VAR Ch,
  280.   AnsiCh : Char;
  281.   Ansi   : Text;
  282. Begin
  283.   Assign(Ansi,'');
  284.   ReWrite(Ansi);
  285.   Repeat
  286.      If Keypressed then
  287.      Begin
  288.        Ch := Readkey;
  289.        If Ch <> Esc then
  290.           ComWriteChar(Port,ch)
  291.      End;
  292.      If CharWaiting(Port) then
  293.      Begin
  294.         AnsiCh := ComReadChar(Port);
  295.         If FossilPresent then
  296.         Asm
  297.           mov ah,13h
  298.           mov al,ansich
  299.           int 14h
  300.         End else
  301.         Write(Ansi,AnsiCh)          { no fossil driver }
  302.      End
  303.   Until Ch = Esc;
  304.   Close(Ansi)
  305. End;
  306.  
  307. Procedure ComWrite(Port : Word; Msg : String);
  308. VAR Dummy, x,
  309.     SegMsg,
  310.     OfsMsg : Word;
  311.     Ansich : Char;
  312.     Ansi   : Text;
  313. Begin
  314.   Assign(Ansi,'');
  315.   ReWrite(Ansi);
  316.   Dummy := Ord(Msg[0]);             { length (msg) }
  317.   If FossilPresent then
  318.   Begin
  319.     SegMsg := Seg(Msg);
  320.     OfsMsg := Ofs(Msg) + 1;           { don't include length of msg }
  321.     Asm                               { use fossil driver }
  322.       mov ah,19h
  323.       mov dx,port
  324.       mov cx,dummy
  325.       mov es,SegMsg
  326.       mov di,OfsMsg
  327.       int 14h
  328.     End;
  329.     While CharWaiting(Port) do
  330.     Begin
  331.       AnsiCh := ComReadChar(Port);
  332.       Asm
  333.         mov ah,13h
  334.         mov al,ansich
  335.         int 14h
  336.       End
  337.     End
  338.   End else
  339.   For x := 1 to dummy do
  340.   Begin
  341.     ComWriteChar(Port,Msg[x]);
  342.     If CharWaiting(Port) then
  343.       Write(Ansi,ComReadChar(Port))
  344.   End;
  345.   Close(Ansi)
  346. End;
  347.  
  348. Procedure ComWriteln(Port : Word; Msg : String);
  349. Begin
  350.    Msg := Msg + #13 + #10;
  351.    ComWrite(Port, Msg)
  352. End;
  353.  
  354. Procedure Wait(Seconds : Word);
  355. VAR Delay : Word;
  356. Begin
  357.    Delay := ((976 SHL 10) * Seconds) SHR 16;  { (976*1024*seconds)/65536 }
  358.    Asm
  359.      mov ah,86h
  360.      mov cx,delay
  361.      mov dx,0
  362.      int 15h
  363.    End
  364. End;
  365.  
  366. Procedure GetCursor(VAR x, y : Byte);
  367. VAR x1, y1 : Byte;
  368. Begin
  369.   If FossilPresent then
  370.   Asm
  371.     mov ah,12h
  372.     int 14h
  373.     mov x1,dl
  374.     mov y1,dh
  375.   End else
  376.   Asm
  377.     mov ah,03h
  378.     mov bh,00h
  379.     int 10h
  380.     mov x1,dl
  381.     mov y1,dh
  382.   End;
  383.   x := x1; y := y1
  384. End;
  385.  
  386. Procedure SetCursor(Port : Word; x, y : Byte);
  387. VAR x1,y1 : String;
  388. Begin
  389.   If FossilPresent then
  390.   Asm
  391.     mov ah,11h
  392.     mov dh,y
  393.     mov dl,x
  394.     int 14h
  395.   End else
  396.   Asm
  397.     mov ah,02h
  398.     mov bh,00h
  399.     mov dh,y
  400.     mov dl,x
  401.     int 10h
  402.   End;
  403.   If (CarrierDetected(port)) and (RemoteAnsiDetected(Port)) then
  404.   Begin
  405.     Str(x,x1);
  406.     Str(y,y1);
  407.     ComWrite(Port,' ['+y1+';'+x1+'H')     { ESC[y;xH }
  408.   End
  409. End;
  410.  
  411. Procedure SendBreak(Port : Word); Assembler;
  412. Asm
  413.   mov ah,1ah             {; start sending break }
  414.   mov al,01h
  415.   mov dx,port
  416.   int 14h
  417.   mov ah,86h             {; wait 1 second }
  418.   mov cx,0fh
  419.   mov dx,00h
  420.   int 15h
  421.   mov ah,1ah             {; stop sending break }
  422.   mov al,00h
  423.   mov dx,port
  424.   int 14h
  425.   mov ah,0ah             {; purge input buffer }
  426.   mov dx,port
  427.   int 14h
  428. End;
  429.  
  430. Procedure ComReadln(Port : Word; VAR Msg : String; Count : Byte);
  431. VAR WLength,
  432.     SegMsg,
  433.     OfsMsg : Word;
  434. Begin
  435.    SegMsg := Seg(Msg);
  436.    OfsMsg := Ofs(Msg);
  437.    WLength := Count;
  438.    Asm
  439.      mov ah,18h
  440.      mov di,ofsmsg
  441.      mov es,segmsg
  442.      mov cx,wlength
  443.      mov dx,port
  444.      int 14h
  445.    End;
  446. End;
  447.  
  448. Procedure CLS(Port : Word);
  449. Begin
  450.   ClrScr;
  451.   If CarrierDetected(Port) then
  452.      If RemoteAnsiDetected(Port) then
  453.         ComWrite(Port,' [2J') else
  454.         ComWriteChar(Port,' ');
  455. End;
  456.  
  457. Begin
  458.    Writeln('Fossil Wizard v1.0 by Steve Connet - Jan. 19, 1993');
  459.    Writeln('This is removed when you register.');
  460.    Wait(2)
  461. End.
  462.  
  463.  
  464. (* This is an example of how to use Fossil Wizard *)
  465.  
  466. Uses FWizard, Crt;
  467.  
  468. VAR
  469.          Ch : Char;
  470.        Baud : Word;
  471.  
  472. Begin
  473.   Baud := 2400;    { change this to the appropriate baud }
  474.   ClrScr;
  475.  
  476.   SetCursor(Com2,50,19);
  477.   If FossilPresent then
  478.   Begin
  479.     ActivatePort(Com2);                { wake up fossil driver }
  480.     Write('[FOSSIL PRESENT]')
  481.   End else
  482.   Write('[FOSSIL NOT PRESENT]');
  483.  
  484.   SetCursor(Com2,50,20);
  485.   If SetBaud(Com2,Baud,N81) then       { set baud rate }
  486.      Write('[MODEM READY]') else
  487.      Write('[MODEM NOT RESPONDING]');
  488.  
  489.   SetCursor(Com2,50,21);
  490.   If CarrierDetected(Com2) then
  491.      Write('[CARRIER DETECTED]') else
  492.      Write('[NO CARRIER]');
  493.  
  494.   SetCursor(Com2,50,22);
  495.   If (CarrierDetected(Com2)) and (RemoteAvatarDetected(Com2)) then
  496.     Write('[REMOTE AVATAR DETECTED]') else
  497.     Write('[REMOTE AVATAR NOT DETECTED]');
  498.  
  499.   SetCursor(Com2,50,23);
  500.   If (CarrierDetected(Com2)) and (RemoteAnsiDetected(Com2)) then
  501.     Write('[REMOTE ANSI DETECTED]') else
  502.     Write('[REMOTE ANSI NOT DETECTED]');
  503.  
  504.   SetCursor(Com2,50,24);
  505.   If LocalAnsiDetected then
  506.      Write('[LOCAL ANSI DETECTED]') else
  507.      Write('[LOCAL ANSI NOT DETECTED]');
  508.  
  509.   SetCursor(Com2,0,0);
  510.   Chat(Com2);              { built in chat mode }
  511.   DTR(Com2,Lower);         { lower data terminal ready }
  512.   DeActivatePort(Com2);    { put fossil driver to sleep }
  513.   ClrScr
  514. End.
  515.